package com.lyn.android_custom_view;

import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.SurfaceHolder;
import android.view.View;

import androidx.annotation.NonNull;

import com.lyn.android_custom_view.databinding.ActivityCameraBinding;
import com.lyn.module_custom_base.avtivity.BaseActivity;
import com.lyn.module_custom_camera.FaceHelper;
import com.lyn.module_custom_camera.LynCamera;
import com.lyn.module_custom_camera.NV21ToBitmap;
import com.lyn.module_custom_camera.Size;
import com.lyn.module_custom_camera.YuvUtil;
import com.lyn.module_custom_utils.LogUtil;
import com.lyn.module_custom_view.pieChart.entity.ChartCircleItem;
import com.lyn.module_custom_view.pieChart.entity.ChartHistogramItem;
import com.lyn.module_custom_view.pieChart.entity.ChartLineItem;
import com.lyn.showYUV.ShowYUV;

import java.util.ArrayList;
import java.util.Random;

/**
 * created by lyn at 2021/10/23
 */
public class CameraActivity extends BaseActivity<ActivityCameraBinding> implements LynCamera.CameraViewCallBack, SurfaceHolder.Callback {
    private NV21ToBitmap nv21ToBitmap;
    private ShowYUV showYUV;

    @Override
    public ActivityCameraBinding getBinding() {
        return ActivityCameraBinding.inflate(getLayoutInflater());
    }

    @Override
    public void setBinding(ActivityCameraBinding binding) {
        binding.toolbar.title.setText("摄像头");
        binding.lynCamera.initialize(0,new Size(640,480));
        binding.lynCamera.setCameraViewCallBack(this);
        nv21ToBitmap=new NV21ToBitmap(context);
        showYUV=new ShowYUV();
        SurfaceHolder holder = binding.testSurface.getHolder();
        showYUV.setSurface(holder.getSurface());
        holder.addCallback(this);
    }

    @Override
    public void setListener(ActivityCameraBinding binding) {
        binding.toolbar.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeUI(MainActivity.class);
                finish();
            }
        });

    }

    @Override
    public boolean onBack() {
        return true;
    }


    @Override
    public void onCallback(byte[] data, Size size) {

        showYUV.showData(data,size.getWidth(),size.getWidth());

    }

    @Override
    public void surfaceCreated(@NonNull SurfaceHolder holder) {

    }

    @Override
    public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(@NonNull SurfaceHolder holder) {

    }
}
